package com.ssh.dao;

import com.ssh.entity.Happy;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.hibernate.query.Query;
import java.util.List;
@Repository
@Scope("prototype")
public class HappyDaoImpl implements HappyDao{
    @Autowired
    private SessionFactory sessionFactory = null;

    public List<Happy> getAllhappy() {
       List<Happy> happyList = null;

        Session session = sessionFactory.getCurrentSession();
        Query query = session.createQuery("from Happy");
        happyList=query.getResultList();

        for (Happy u:happyList){
            if (u.getAge()>30){
                System.out.println("您已超龄");
            }else{
                System.out.println("你还小呢");
            }
        }

        return happyList;
    }
}
